from django.db import models
from django.contrib.auth.models import AbstractUser,UserManager as _UserManager

class UserManage(_UserManager):
    def create_superuser(self, username,  password,email=None, **extra_fields):
        super().create_superuser(username=username,password=password,email=email,
                                 **extra_fields)

class User(AbstractUser):
    mobile = models.CharField("手机号",max_length=11,unique=True,help_text="手机号",error_messages={"unique":"该手机号已注册"})
    email_active = models.BooleanField("邮箱",default=True)
    class Meta:
        # 指定数据库库名
        db_table = "tz_user"
        #在admin站点中的显示
        verbose_name = "用户"
        #复数
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.username
    #通过createsuperuser命令创建用户时，必须的字段
    REQUIRED_FIELDS = ["mobile"]
    #模型管理器
    objects = UserManage()